import sys

from PyQt5.QtWidgets import QApplication, QWidget, QLabel

'''
窗体居中及布局
窗体默认在屏幕中心

'''


class MyForm1(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('刘金玉编程教程')
        lb1 = QLabel('编程创造城市', self)
        self.resize(400, 300)
        self.show()
        self.center()

    def center(self):
        # 获取桌面窗口宽高
        desk_w = 1920 or app.desktop().width()  # 双屏幕会连加在一起
        desk_h = app.desktop().height()
        # 获取win窗口大小
        # self.width()
        self.move(desk_w/2-self.width()/2, desk_h/2-self.height()/2-15)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    # 获取桌面窗口宽高
    # desk_w = 1920 or app.desktop().width()
    # desk_h = app.desktop().height()
    # print(app.desktop().height())
    mf1 = MyForm1()
    # mf1.move(desk_w / 2 - mf1.width() / 2, desk_h / 2 - mf1.height() / 2 - 15)
    app.exec_()
